package com.niit.xlztest.service;

import com.niit.xlztest.bean.Book;
import com.niit.xlztest.bean.BorrowRecord;
import com.niit.xlztest.bean.Shopping_cart;
import com.niit.xlztest.repository.BookRepository;
import com.niit.xlztest.repository.BuyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service("BuyService")
public class BuyServiceImpl implements BuyService{
    @Autowired
    private BuyRepository buyRepository;

    @Override
    public void buyBook(Integer book_id) {
        //用于给销量+1
        buyRepository.buyBook(book_id);
    }
    @Override
    public List<Shopping_cart> findAllBookInCart(Integer user_id){
        return (List<Shopping_cart>) buyRepository.findAllBookInCart(user_id);
    }
    @Override
    public void deleteByUserIdAndBookId(Integer userId, Integer bookId){
        buyRepository.deleteByUserIdAndBookId(userId,bookId);
    };

    @Override
    public void cart(Shopping_cart shopping_cart) {
        buyRepository.save(shopping_cart);
    }
}
